package edu.ucsc.mit2008.swan.editor.coreUI.internal.wizard.page;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;

import edu.ucsc.mit2008.swan.editor.coreUI.internal.template.dialog.EditTemplateDialog;

public class ManageTemplatesWizardPageUI extends Composite {

	private Tree templatesTree;
	private TreeViewer templayesTreeViewer;
	
	private Button addButton;
	private Button editButton;
	private Button removeButton;
	
	public ManageTemplatesWizardPageUI(Composite parent, int style) {
		super(parent, style);
		createDetailsComposite(this, style);
	}

	private Composite createDetailsComposite(Composite container, int style) {
		GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container);
		templatesTree = new Tree(container, SWT.BORDER);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(templatesTree);
		templayesTreeViewer = new TreeViewer(templatesTree);
		
		Composite btnComposite = new Composite(container, SWT.NONE);
		GridLayoutFactory.fillDefaults().equalWidth(false).applyTo(btnComposite);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(btnComposite);
		createButtons(btnComposite);
		return container;
	}
	
	private void createButtons(Composite parentComposite){
		addButton = new Button(parentComposite, SWT.PUSH);
		addButton.setText("Add Template");
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addButton);
		addButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				EditTemplateDialog dialog = new EditTemplateDialog(getShell());
				dialog.open();
			}
			
		});

		editButton = new Button(parentComposite, SWT.PUSH);
		editButton.setText("Edit Template");
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(editButton);
		

		removeButton = new Button(parentComposite, SWT.PUSH);
		removeButton.setText("Remove Template");
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(removeButton);
	}
}
